//
//  SendFriendViewController.m
//  huanxin
//
//  Created by 郭亚 on 16/4/28.
//  Copyright © 2016年 郭亚. All rights reserved.
//

#import "SendFriendViewController.h"

#import <EaseMob.h>

@interface SendFriendViewController ()

@property (nonatomic, strong) UITextField *textField;

@property (nonatomic, strong) UIButton *addButton;

@end

@implementation SendFriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createView];
    self.navigationItem.title = @"添加好友";
}

- (void)createView
{
    _textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 120, self.view.frame.size.width - 20, 40)];
    _textField.textAlignment = NSTextAlignmentCenter;
    _textField.layer.borderWidth = 2;
    _textField.layer.borderColor = [UIColor orangeColor].CGColor;
    _textField.layer.cornerRadius = 10;
    _textField.placeholder = @"请输入账号";
    [self.view addSubview:_textField];
    
    _addButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(_textField.frame), CGRectGetMaxY(_textField.frame) + 20, _textField.frame.size.width, _textField.frame.size.height)];
    _addButton.layer.cornerRadius = 10;
    _addButton.backgroundColor = [UIColor orangeColor];
    [_addButton setTitle:@"添加" forState:(UIControlStateNormal)];
    [_addButton addTarget:self action:@selector(addButtonClicked) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_addButton];
    
}

- (void)addButtonClicked
{
    EMError *error = nil;
    BOOL succeed = [[EaseMob sharedInstance].chatManager addBuddy:self.textField.text message:@"客官, 加我" error:&error];
    if (succeed && !error) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
